import { useCallback } from "react";
import { useState } from "react";
import Child1 from "./UseCallbackChid";

const Parent = () => {
  const [todoList,setToList] = useState([
    {
      title: '标题'
    }
  ])
  const [name,setname] = useState(1)

  const updateName = () => {
    setname(name + 1)
  }
  const updateList = useCallback((msg) => {
    let nList = [...todoList]
    nList.push(msg)
    setToList(nList)
  },[todoList])
  return (<div>
    name:{name}<br />
    <button onClick={updateName}>更新name</button>
    渲染todoList
    {
      todoList.map((item,key) => <p key={key}>{item.title}</p>)
    }
    <Child1 updateList={updateList} />
  </div>)
}

export default Parent